package com.gzist.elderlyserviceplatform.controller.client;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.entity.dto.InfoNewsQueryByCategoryDTO;
import com.gzist.elderlyserviceplatform.entity.po.InfoNews;
import com.gzist.elderlyserviceplatform.entity.vo.InfoNewsQueryByCategoryVO;
import com.gzist.elderlyserviceplatform.entity.vo.InfoNewsQueryByLatestOrHotVO;
import com.gzist.elderlyserviceplatform.service.InfoNewsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资讯信息表
 */
@RestController
@Tag(name = "资讯信息管理")
@RequestMapping("/api/client/infoNews")
@RequiredArgsConstructor
public class InfoNewsControllerC {

    private final InfoNewsService infoNewsService;

    @GetMapping("/latestOrHot/{id}")
    @Operation(
            summary = "首页最新最热资讯",
            description = "根据入参id进行过滤查询资讯信息列表，1=》最新资讯，2=》最热资讯"
    )
    public Result<List<InfoNewsQueryByLatestOrHotVO>> listByLatestOrHot(
            @PathVariable
            @Parameter(description = "过滤条件id") String id
    ) {
        return Result.success(infoNewsService.listByLatestOrHot(id), "查询成功");
    }

    @PostMapping("/listByCategory")
    @Operation(
            summary = "首页分类组资讯列表"
    )
    public Result<Page<InfoNewsQueryByCategoryVO>> queryPageByCategory(
            @RequestBody
            @Parameter(description = "查询参数") InfoNewsQueryByCategoryDTO dto
    ) {
        return Result.success(infoNewsService.queryPageByCategory(dto), "查询成功");
    }

    /**
     * 首页获取资讯详情
     *
     * @param id 资讯 ID
     * @return 资讯详情
     */
    @GetMapping("/detail/{id}")
    @Operation(
            summary = "首页资讯详情",
            description = "根据资讯 ID 查询资讯详情"
    )
    public Result<InfoNews> getNewsDetail(
            @PathVariable
            @Parameter(description = "资讯id") String id
    ) {
        return Result.success(infoNewsService.getNewsDetail(id), "查询成功");
    }
}